<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"mixley.github.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="查看死锁-- 查询死锁1select  request_session_id spid,    OBJECT_NAME(resource_associated_entity_id) tableName    from   sys.dm_tran_locks   where     resource_type&#x3D;&amp;#x27;OBJECT&amp;#x27;    -- 查询死锁2SELECT [session">
<meta property="og:type" content="article">
<meta property="og:title" content="sqlserver">
<meta property="og:url" content="https://mixley.github.io/2022/3M68A3M.html">
<meta property="og:site_name" content="mixley">
<meta property="og:description" content="查看死锁-- 查询死锁1select  request_session_id spid,    OBJECT_NAME(resource_associated_entity_id) tableName    from   sys.dm_tran_locks   where     resource_type&#x3D;&amp;#x27;OBJECT&amp;#x27;    -- 查询死锁2SELECT [session">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2022-06-12T06:35:17.422Z">
<meta property="article:modified_time" content="2022-02-24T01:55:03.000Z">
<meta property="article:author" content="mixley">
<meta property="article:tag" content="java">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://mixley.github.io/2022/3M68A3M.html">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>sqlserver | mixley</title>
  


  <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?c36eb18366b436984557126f16796f30";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">mixley</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">求上者得中·求中者得下</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-sitemap">

    <a href="/sitemap.xml" rel="section"><i class="fa fa-sitemap fa-fw"></i>站点地图</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://mixley.github.io/2022/3M68A3M.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="mixley">
      <meta itemprop="description" content="全栈·架构设计·算法">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="mixley">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          sqlserver
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-06-12 14:35:17" itemprop="dateCreated datePublished" datetime="2022-06-12T14:35:17+08:00">2022-06-12</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-02-24 09:55:03" itemprop="dateModified" datetime="2022-02-24T09:55:03+08:00">2022-02-24</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/operations/" itemprop="url" rel="index"><span itemprop="name">运维</span></a>
                </span>
                  ，
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/operations/sql/" itemprop="url" rel="index"><span itemprop="name">sql</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Changyan：</span>
    
    
      <a title="changyan" href="/2022/3M68A3M.html#SOHUCS" itemprop="discussionUrl">
        <span id="changyan_count_unit" class="post-comments-count hc-comment-count" data-xid="2022/3M68A3M.html" itemprop="commentCount"></span>
      </a>
    
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="查看死锁"><a href="#查看死锁" class="headerlink" title="查看死锁"></a>查看死锁</h2><figure class="highlight sql"><table><tr><td class="code"><pre><span class="line"><span class="comment">-- 查询死锁1</span></span><br><span class="line"><span class="keyword">select</span> </span><br><span class="line"> request_session_id spid,   </span><br><span class="line"> OBJECT_NAME(resource_associated_entity_id) tableName    </span><br><span class="line"><span class="keyword">from</span> </span><br><span class="line">  sys.dm_tran_locks   </span><br><span class="line"><span class="keyword">where</span> </span><br><span class="line">    resource_type<span class="operator">=</span><span class="string">&#x27;OBJECT&#x27;</span></span><br><span class="line">    </span><br><span class="line"><span class="comment">-- 查询死锁2</span></span><br><span class="line"><span class="keyword">SELECT</span> </span><br><span class="line">[session_id],</span><br><span class="line">[request_id],</span><br><span class="line">[start_time] <span class="keyword">AS</span> <span class="string">&#x27;开始时间&#x27;</span>,</span><br><span class="line">[status] <span class="keyword">AS</span> <span class="string">&#x27;状态&#x27;</span>,</span><br><span class="line">[command] <span class="keyword">AS</span> <span class="string">&#x27;命令&#x27;</span>,</span><br><span class="line">dest.[text] <span class="keyword">AS</span> <span class="string">&#x27;sql语句&#x27;</span>, </span><br><span class="line">DB_NAME([database_id]) <span class="keyword">AS</span> <span class="string">&#x27;数据库名&#x27;</span>,</span><br><span class="line">[blocking_session_id] <span class="keyword">AS</span> <span class="string">&#x27;正在阻塞其他会话的会话ID&#x27;</span>,</span><br><span class="line">[wait_type] <span class="keyword">AS</span> <span class="string">&#x27;等待资源类型&#x27;</span>,</span><br><span class="line">[wait_time] <span class="keyword">AS</span> <span class="string">&#x27;等待时间&#x27;</span>,</span><br><span class="line">[wait_resource] <span class="keyword">AS</span> <span class="string">&#x27;等待的资源&#x27;</span>,</span><br><span class="line">[<span class="keyword">reads</span>] <span class="keyword">AS</span> <span class="string">&#x27;物理读次数&#x27;</span>,</span><br><span class="line">[writes] <span class="keyword">AS</span> <span class="string">&#x27;写次数&#x27;</span>,</span><br><span class="line">[logical_reads] <span class="keyword">AS</span> <span class="string">&#x27;逻辑读次数&#x27;</span>,</span><br><span class="line">[row_count] <span class="keyword">AS</span> <span class="string">&#x27;返回结果行数&#x27;</span></span><br><span class="line"><span class="keyword">FROM</span> sys.[dm_exec_requests] <span class="keyword">AS</span> der </span><br><span class="line"><span class="keyword">CROSS</span> APPLY </span><br><span class="line">sys.[dm_exec_sql_text](der.[sql_handle]) <span class="keyword">AS</span> dest </span><br><span class="line"><span class="keyword">ORDER</span> <span class="keyword">BY</span> [cpu_time] <span class="keyword">DESC</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="根据spid查询执行的sql语句"><a href="#根据spid查询执行的sql语句" class="headerlink" title="根据spid查询执行的sql语句"></a>根据spid查询执行的sql语句</h2><figure class="highlight sql"><table><tr><td class="code"><pre><span class="line"><span class="comment">-- sp_who2查询出的spid</span></span><br><span class="line"><span class="comment">-- 查进程执行的语句1</span></span><br><span class="line"><span class="comment">-- 根据spid来查询执行的SQL语句</span></span><br><span class="line"><span class="keyword">select</span> er.session_id,<span class="built_in">CAST</span>(csql.text <span class="keyword">AS</span> <span class="type">varchar</span>(<span class="number">255</span>)) <span class="keyword">AS</span> CallingSQL</span><br><span class="line"><span class="keyword">from</span> master.sys.dm_exec_requests er</span><br><span class="line"><span class="keyword">WITH</span> (NOLOCK)</span><br><span class="line"> <span class="keyword">CROSS</span> APPLY MASTER.sys.fn_get_sql (er.sql_handle) csql</span><br><span class="line"><span class="keyword">where</span> er.session_id <span class="operator">=</span><span class="variable">@spid</span></span><br><span class="line"></span><br><span class="line"><span class="comment">-- 查进程执行的语句2</span></span><br><span class="line">DBCC INPUTBUFFER(<span class="variable">@spid</span>)</span><br></pre></td></tr></table></figure>



<h2 id="字段属性生成-依据表名生成excel表样"><a href="#字段属性生成-依据表名生成excel表样" class="headerlink" title="字段属性生成(依据表名生成excel表样)"></a>字段属性生成(依据表名生成excel表样)</h2><figure class="highlight sql"><table><tr><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> 表名 <span class="operator">=</span> <span class="keyword">case</span> <span class="keyword">when</span> a.colorder <span class="operator">=</span> <span class="number">1</span> <span class="keyword">then</span> d.name <span class="keyword">else</span> <span class="string">&#x27;&#x27;</span> <span class="keyword">end</span>,</span><br><span class="line"> 字段名称 <span class="operator">=</span> a.name,</span><br><span class="line"> 字段类型 <span class="operator">=</span> b.name <span class="operator">+</span> <span class="string">&#x27;(&#x27;</span> <span class="operator">+</span> <span class="built_in">cast</span>(COLUMNPROPERTY(a.id, a.name, <span class="string">&#x27;PRECISION&#x27;</span>) <span class="keyword">AS</span> <span class="type">VARCHAR</span>(<span class="number">10</span>)) <span class="operator">+</span> <span class="string">&#x27;)&#x27;</span>,</span><br><span class="line"> 约束 <span class="operator">=</span> <span class="keyword">case</span></span><br><span class="line">    <span class="keyword">when</span> <span class="keyword">exists</span>(<span class="keyword">SELECT</span> <span class="number">1</span></span><br><span class="line">    <span class="keyword">FROM</span> sysobjects</span><br><span class="line">    <span class="keyword">where</span> xtype <span class="operator">=</span> <span class="string">&#x27;PK&#x27;</span></span><br><span class="line">      <span class="keyword">and</span> parent_obj <span class="operator">=</span> a.id</span><br><span class="line">      <span class="keyword">and</span> name <span class="keyword">in</span> (</span><br><span class="line">        <span class="keyword">SELECT</span> name</span><br><span class="line">        <span class="keyword">FROM</span> sysindexes</span><br><span class="line">        <span class="keyword">WHERE</span> indid <span class="keyword">in</span> (<span class="keyword">SELECT</span> indid</span><br><span class="line">           <span class="keyword">FROM</span> sysindexkeys <span class="keyword">as</span> ind</span><br><span class="line">            <span class="keyword">WHERE</span> ind.id <span class="operator">=</span> a.id</span><br><span class="line">        <span class="keyword">AND</span> ind.colid <span class="operator">=</span> a.colid))) <span class="keyword">then</span> <span class="string">&#x27;主键&#x27;</span></span><br><span class="line">    <span class="keyword">when</span> <span class="keyword">exists</span>(<span class="keyword">SELECT</span> <span class="number">1</span></span><br><span class="line">    <span class="keyword">FROM</span> sysobjects</span><br><span class="line">    <span class="keyword">where</span> xtype <span class="operator">=</span> <span class="string">&#x27;F&#x27;</span></span><br><span class="line">      <span class="keyword">and</span> parent_obj <span class="operator">=</span> a.id</span><br><span class="line">      <span class="keyword">and</span> name <span class="keyword">in</span> (</span><br><span class="line">        <span class="keyword">SELECT</span> name</span><br><span class="line">        <span class="keyword">FROM</span> sysindexes</span><br><span class="line">        <span class="keyword">WHERE</span> indid <span class="keyword">in</span> (<span class="keyword">SELECT</span> indid</span><br><span class="line">          <span class="keyword">FROM</span> sysforeignkeys <span class="keyword">as</span> fore</span><br><span class="line">          <span class="keyword">WHERE</span> fore.fkey <span class="operator">=</span> a.id</span><br><span class="line">        <span class="keyword">AND</span> fore.rkey <span class="operator">=</span> a.colid))) <span class="keyword">then</span> <span class="string">&#x27;外键&#x27;</span></span><br><span class="line">    <span class="keyword">else</span> <span class="string">&#x27;&#x27;</span> <span class="keyword">end</span>,</span><br><span class="line"> 是否为空 <span class="operator">=</span> <span class="keyword">case</span> <span class="keyword">when</span> a.isnullable <span class="operator">=</span> <span class="number">1</span> <span class="keyword">then</span> <span class="string">&#x27;&#x27;</span> <span class="keyword">else</span> <span class="string">&#x27;NOT NULL&#x27;</span> <span class="keyword">end</span>,</span><br><span class="line"> 中文说明 <span class="operator">=</span> isnull(e.text, <span class="string">&#x27;&#x27;</span>),</span><br><span class="line"> 注释 <span class="operator">=</span> isnull(g.[<span class="keyword">value</span>], <span class="string">&#x27;&#x27;</span>)</span><br><span class="line"><span class="keyword">FROM</span> syscolumns a</span><br><span class="line">   <span class="keyword">left</span> <span class="keyword">join</span></span><br><span class="line">     systypes b</span><br><span class="line">     <span class="keyword">on</span></span><br><span class="line">   a.xusertype <span class="operator">=</span> b.xusertype</span><br><span class="line">   <span class="keyword">inner</span> <span class="keyword">join</span></span><br><span class="line">     sysobjects d</span><br><span class="line">     <span class="keyword">on</span></span><br><span class="line">   a.id <span class="operator">=</span> d.id <span class="keyword">and</span> d.xtype <span class="operator">=</span> <span class="string">&#x27;U&#x27;</span> <span class="keyword">and</span> d.name <span class="operator">&lt;&gt;</span> <span class="string">&#x27;dtproperties&#x27;</span></span><br><span class="line">   <span class="keyword">left</span> <span class="keyword">join</span></span><br><span class="line">     syscomments e</span><br><span class="line">     <span class="keyword">on</span></span><br><span class="line">   a.cdefault <span class="operator">=</span> e.id</span><br><span class="line">   <span class="keyword">left</span> <span class="keyword">join</span></span><br><span class="line">     sys.extended_properties g</span><br><span class="line">     <span class="keyword">on</span></span><br><span class="line">   a.id <span class="operator">=</span> G.major_id <span class="keyword">and</span> a.colid <span class="operator">=</span> g.minor_id</span><br><span class="line">   <span class="keyword">left</span> <span class="keyword">join</span></span><br><span class="line">     sys.extended_properties f</span><br><span class="line">     <span class="keyword">on</span></span><br><span class="line">   d.id <span class="operator">=</span> f.major_id <span class="keyword">and</span> f.minor_id <span class="operator">=</span> <span class="number">0</span></span><br><span class="line"><span class="keyword">where</span> d.name <span class="operator">=</span> <span class="variable">@tablename</span> <span class="comment">-- 如果只查询指定表,加上此红色where条件，tablename是要查询的表名；去除红色where条件查询说有的表信息</span></span><br><span class="line"><span class="keyword">order</span> <span class="keyword">by</span> a.id, a.colorder</span><br></pre></td></tr></table></figure>

<h2 id="JavaBean生成"><a href="#JavaBean生成" class="headerlink" title="JavaBean生成"></a>JavaBean生成</h2><figure class="highlight sql"><table><tr><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="string">&#x27;/**&#x27;</span><span class="operator">+</span><span class="type">char</span>(<span class="number">13</span>)<span class="operator">+</span><span class="type">char</span>(<span class="number">10</span>)  </span><br><span class="line"><span class="operator">+</span><span class="string">&#x27;*&#x27;</span><span class="operator">+</span>isnull(<span class="keyword">CONVERT</span>(<span class="type">VARCHAR</span>(<span class="number">100</span>),g.value),<span class="string">&#x27;&#x27;</span>) <span class="operator">+</span> <span class="type">char</span>(<span class="number">13</span>)<span class="operator">+</span><span class="type">char</span>(<span class="number">10</span>)  </span><br><span class="line"><span class="operator">+</span><span class="string">&#x27;*/&#x27;</span><span class="operator">+</span><span class="type">char</span>(<span class="number">13</span>)<span class="operator">+</span><span class="type">char</span>(<span class="number">10</span>)  </span><br><span class="line"><span class="operator">+</span><span class="string">&#x27;private &#x27;</span><span class="operator">+</span>  </span><br><span class="line"><span class="keyword">case</span> b.name <span class="keyword">when</span>   </span><br><span class="line"><span class="string">&#x27;int&#x27;</span> <span class="keyword">then</span> <span class="string">&#x27;Integer&#x27;</span>  </span><br><span class="line"><span class="keyword">when</span> <span class="string">&#x27;varchar&#x27;</span> <span class="keyword">then</span> <span class="string">&#x27;String&#x27;</span>  </span><br><span class="line"><span class="keyword">when</span> <span class="string">&#x27;nvarchar&#x27;</span> <span class="keyword">then</span> <span class="string">&#x27;String&#x27;</span>  </span><br><span class="line"><span class="keyword">when</span> <span class="string">&#x27;text&#x27;</span> <span class="keyword">then</span> <span class="string">&#x27;String&#x27;</span>  </span><br><span class="line"><span class="keyword">when</span> <span class="string">&#x27;float&#x27;</span> <span class="keyword">then</span> <span class="string">&#x27;Double&#x27;</span>  </span><br><span class="line"><span class="keyword">when</span> <span class="string">&#x27;numeric&#x27;</span> <span class="keyword">then</span> <span class="string">&#x27;Float&#x27;</span>  </span><br><span class="line"><span class="keyword">when</span> <span class="string">&#x27;datetime&#x27;</span> <span class="keyword">then</span> <span class="string">&#x27;Date&#x27;</span> </span><br><span class="line"><span class="keyword">when</span> <span class="string">&#x27;decimal&#x27;</span> <span class="keyword">then</span> <span class="string">&#x27;BigDecimal&#x27;</span> </span><br><span class="line"><span class="keyword">else</span> b.name <span class="keyword">end</span>  </span><br><span class="line"><span class="operator">+</span><span class="string">&#x27; &#x27;</span><span class="operator">+</span>a.name <span class="comment">-- 保持字段名称的原始大小写则直接用a.name  </span></span><br><span class="line"><span class="operator">+</span><span class="string">&#x27;;&#x27;</span><span class="operator">+</span><span class="type">char</span>(<span class="number">13</span>)<span class="operator">+</span><span class="type">char</span>(<span class="number">10</span>)<span class="operator">+</span><span class="type">char</span>(<span class="number">13</span>)<span class="operator">+</span><span class="type">char</span>(<span class="number">10</span>)  </span><br><span class="line"><span class="comment">--,b.name,a.max_length ,g.value,b.name,a.name  </span></span><br><span class="line"><span class="keyword">from</span> sys.columns a <span class="keyword">left</span> <span class="keyword">join</span> sys.types b <span class="keyword">on</span> a.user_type_id<span class="operator">=</span>b.user_type_id   </span><br><span class="line"><span class="keyword">left</span> <span class="keyword">join</span> sys.extended_properties g <span class="keyword">on</span> a.object_id<span class="operator">=</span>g.major_id <span class="keyword">and</span> a.column_id<span class="operator">=</span>g.minor_id  </span><br><span class="line"><span class="keyword">where</span> object_id<span class="operator">=</span>object_id(<span class="variable">@tablename</span>) ; <span class="comment">-- 其中@tablename为表名</span></span><br></pre></td></tr></table></figure>


    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/java/" rel="tag"># java</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2022/T8RYR0.html" rel="prev" title="jmx">
      <i class="fa fa-chevron-left"></i> jmx
    </a></div>
      <div class="post-nav-item"></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    
  <div class="comments">
    <div id="SOHUCS"></div>
  </div>
  

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E6%AD%BB%E9%94%81"><span class="nav-number">1.</span> <span class="nav-text">查看死锁</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%A0%B9%E6%8D%AEspid%E6%9F%A5%E8%AF%A2%E6%89%A7%E8%A1%8C%E7%9A%84sql%E8%AF%AD%E5%8F%A5"><span class="nav-number">2.</span> <span class="nav-text">根据spid查询执行的sql语句</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AD%97%E6%AE%B5%E5%B1%9E%E6%80%A7%E7%94%9F%E6%88%90-%E4%BE%9D%E6%8D%AE%E8%A1%A8%E5%90%8D%E7%94%9F%E6%88%90excel%E8%A1%A8%E6%A0%B7"><span class="nav-number">3.</span> <span class="nav-text">字段属性生成(依据表名生成excel表样)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#JavaBean%E7%94%9F%E6%88%90"><span class="nav-number">4.</span> <span class="nav-text">JavaBean生成</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">mixley</p>
  <div class="site-description" itemprop="description">全栈·架构设计·算法</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">43</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">19</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">10</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">mixley</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  

  <script>
  NexT.utils.loadComments(document.querySelector('#SOHUCS'), () => {
    var appid = 'cyvxnSprz';
    var conf = 'prod_45d8f2d8bd5b14b5c44442e45f977f85';
    var width = window.innerWidth || document.documentElement.clientWidth;
    if (width < 960) {
      window.document.write('<script id="changyan_mobile_js" charset="utf-8" type="text/javascript" src="https://changyan.sohu.com/upload/mobile/wap-js/changyan_mobile.js?client_id=' + appid + '&conf=' + conf + '"><\/script>');
    } else {
      var loadJs=function(d,a){var c=document.getElementsByTagName("head")[0]||document.head||document.documentElement;var b=document.createElement("script");b.setAttribute("type","text/javascript");b.setAttribute("charset","UTF-8");b.setAttribute("src",d);if(typeof a==="function"){if(window.attachEvent){b.onreadystatechange=function(){var e=b.readyState;if(e==="loaded"||e==="complete"){b.onreadystatechange=null;a()}}}else{b.onload=a}}c.appendChild(b)};loadJs("https://changyan.sohu.com/upload/changyan.js",function(){window.changyan.api.config({appid:appid,conf:conf})});
    }
  });
  </script>
  <script src="https://assets.changyan.sohu.com/upload/plugins/plugins.count.js"></script>

</body>
</html>
